# coding=utf-8
import download
# import series
import httpclient
import config

from bs4 import BeautifulSoup

html = download.download("https://www.guazi.com/bj/buy/", 2)
soup = BeautifulSoup(html)
num = 0
zhongwen = '不限'
list = []
for k in soup.find_all('a'):
    d = dict()
    kvalue = k.get('href', default=None)
    if kvalue is None:
        continue
    if k['href'] == '/bj/buy/#bread' and k.string == zhongwen.decode('utf-8', 'strict'):
        num += 1
        if k['href'] == '/bj/buy/#bread':
            continue
    # 根据不限判断条件筛选1、品牌2、车系
    if num == 1:
        name = k.string.strip()
        url = k['href']
        d.setdefault("brandName", name)
        d.setdefault("brandUrl", url)
        list.append(d)
        # 品牌下型号查询
httpclient.sendJson(list, config.getConfig("url", "insertBrand"))

